PDFDocument.LoadJPEGImage Method (console safe)
Loads a JPEG image into the PDF document from a string buffer. The image will be stored as native JPG in the PDF document, making the compression of it very good.

LoadJPEGImage(
imageBuffer
as String)
as Image
Parameters
- imageBuffer
- The string buffer representing the JPEG image.
Returns
- Image
- Image object if successful, else nil. Nil can be returned for example if the string did not actually represent JPEG image buffer.
Remarks
JPEG’s are stored in native JPEG compressed format in the PDF so they will make the document grow far less than if putting RawBitmap into the PDF document.
Example
using EinhugurPDFWriter
Dim pdf as PDFDocument
Dim f as FolderItem
Dim image as Image
Dim stream as BinaryStream
f = GetFileAtRoot("IMG_0094.JPG")
if f = nil or not f.Exists then
MsgBox "Could not find the image"
return
end if
stream = BinaryStream.Open(f)
if stream <> nil then
while not stream.EOF
imageData = imageData + stream.Read(4096)
wend
stream.Close()
else
MsgBox "Could not open stream"
end if
pdf = new PDFDocument()
image = pdf.LoadJPEGImage(imageData)
myPage = pdf.AddPage()
myPage.SetSize(Page.PageSizeEnum.A4,Page.PageDirectionEnum.PORTRAIT)
myPage.DrawImage(image, (myPage.Width / 2) - (image.Width / 2), 250, image.Width, image.Height)
f = GetSaveFolderItem("*.*","MyPDF.pdf")
if f <> nil then
if f.Exists then
f.Delete()
end if
pdf.Save(f)
end if
See Also
PDFDocument Class